<%@ page language="java" contentType="text/html;charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix='fmt' uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<head>
    <jsp:include page="../common/common.jsp"/>
    <link href="${path}/assets/css/plugins.css" rel="stylesheet" type="text/css"/>
</head>
<body class="page-header-fixed">
<jsp:include page="../common/header.jsp"/>
<div class="clearfix">
</div>
<div class="page-container">
    <div class="page-sidebar-wrapper"><jsp:include page="../common/menu.jsp"/></div>
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12">
                    <form class="form-horizontal form-row-seperated" action="${path}/business/update" method="POST">
                        <div class="portlet box purple">
                            <div class="portlet-title">
                                <div class="caption">
                                    <i class="fa fa-shopping-cart"></i>商机基本信息
                                </div>
                                <div class="actions btn-set">
                                    <button type="button" id="btnSave" class="btn blue"><i class="fa fa-check"></i> 保存
                                    </button>
                                    <button type="button" id="btnDel" class="btn red"><i class="fa fa-share"></i> 删除
                                    </button>
                                </div>
                            </div>
                            <div class="portlet-body">
                                <div class="tabbable">
                                    <div class="tab-content no-space">
                                        <div class="tab-pane active" id="tab_general">
                                            <div class="form-body">
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">标题:</label>
                                                    <div class="col-md-8">
                                                        <input class="form-control" name="summary" datatype="*"
                                                               value="${data.summary}"/>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">姓名:</label>

                                                    <div class="col-md-3">
                                                        <input type="text" class="form-control" name="userName"
                                                               datatype="*" value="${data.userName}">
                                                    </div>
                                                    <label class="col-md-2 control-label">联系电话:</label>
                                                    <div class="col-md-3">
                                                        <input type="text" class="form-control" name="telephone"
                                                               datatype="n" ignore="ignore" value="${data.telephone}">
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">代理地区:
                                                        <span class="required">*</span>
                                                    </label>
                                                    <div class="col-md-2">
                                                        <select id="province" name="province" class="form-control"></select>
                                                    </div>
                                                    <div class="col-md-3">
                                                        <select id="city" name="city" class="form-control"></select>
                                                    </div>
                                                    <div class="col-md-3">
                                                        <select id="county" name="county" class="form-control"></select>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">乡/镇:</label>
                                                    <div class="col-md-8">
                                                        <input type="text" class="form-control" name="address"
                                                               value="${data.address}">
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">面积:</label>
                                                    <div class="col-md-3">
                                                        <input type="text" class="form-control" name="acreage"
                                                               datatype="n|/^-?\d+\.\d+$/" ignore="ignore"
                                                               value="${data.acreage}">
                                                    </div>
                                                    <label class="col-md-2 control-label">投入金额:
                                                    </label>
                                                    <div class="col-md-3">
                                                        <input type="text" class="form-control" name="inmoney"
                                                               datatype="n|/^-?\d+\.\d+$/" ignore="ignore"
                                                               value="${data.inmoney}">
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">分类:
                                                        <span class="required">*</span>
                                                    </label>
                                                    <div class="col-md-8 radio-list">
                                                        <table id="classId">
                                                            <c:forEach items="${classList}" var="data" varStatus="status">
                                                                <c:if test="${status.index!=0 && status.index%8==0}"><tr></c:if>
                                                                <td>
                                                                    <label class="radio-inline">
                                                                        <input type="radio" name="classId" value="${data.id}">
                                                                    </label>
                                                                </td>
                                                                <td>${data.value0}</td>
                                                                <c:if test="${status.index!=0 && status.count%8==0}"></tr></c:if>
                                                            </c:forEach>
                                                        </table>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">品类:
                                                        <span class="required">*</span>
                                                    </label>
                                                    <div class="col-md-8 radio-list">
                                                        <table id="pinlei">
                                                            <tr>
                                                                <td>暂无品类！</td>
                                                            </tr>
                                                        </table>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">代理档次:
                                                    </label>
                                                    <div class="col-md-8">
                                                        <input type="text" class="form-control" name="agentsGrade"
                                                               value="${data.agentsGrade}">
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">星数/价格:
                                                        <span class="required">*</span>
                                                    </label>
                                                    <div class="col-md-3">
                                                        <select id="price" name="price" class="form-control">
                                                            <c:forEach begin="1" end="10" step="1" var="bl">
                                                            <option
                                                                    <c:if test="${bl==data.price}">selected="selected" </c:if>
                                                                    value="${bl}">${bl}
                                                                </c:forEach>
                                                        </select>
                                                    </div>
                                                    <label class="col-md-2 control-label">库存:
                                                        <span class="required">*</span>
                                                    </label>

                                                    <div class="col-md-3">
                                                        <select name="stock" class="form-control">
                                                            <c:forEach begin="1" end="10" step="1" var="bl">
                                                            <option
                                                                    <c:if test="${bl== data.stock }">selected="selected" </c:if>
                                                                    value="${bl}">${bl}
                                                                </c:forEach>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">开业时间:
                                                        <span class="required">*</span>
                                                    </label>
                                                    <div class="col-md-3">
                                                        <input type="text" class="form-control" name="opeanDate"
                                                               value="${data.opeanDate}" readonly="readonly"
                                                               onclick="WdatePicker({dateFmt:'yyyy-MM'})"/>
                                                    </div>
                                                    <label class="col-md-2 control-label">失效时间:
                                                        <span class="required">*</span>
                                                    </label>
                                                    <div class="col-md-3">
                                                        <input type="text" class="form-control" name="expiryDate"
                                                               value='<fmt:formatDate value="${data.expiryDate}" type="date"/>' readonly="readonly"
                                                               onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">关键字:</label>
                                                    <div class="col-md-8">
                                                        <input class="form-control"
                                                                  name="keyword" value="${data.keyword}"/>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-md-2 control-label">详细信息:</label>
                                                    <div class="col-md-8">
                                                        <textarea class="form-control"
                                                                  name="agentDetails">${data.agentDetails}</textarea>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="portlet-title">
                                <div class="actions btn-set">
                                    <button type="button" id="btnSave" class="btn blue"><i class="fa fa-check"></i> 保存
                                    </button>
                                    <button type="button" id="btnDel" class="btn red"><i class="fa fa-share"></i> 删除
                                    </button>
                                </div>
                            </div>
                        </div>
                        <input type="hidden" name="id" value="${data.id}">
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<jsp:include page="../common/footer.jsp"/>
<script type="text/javascript" src="${path}/assets/plugins/calendar/WdatePicker.js"></script>
<script type="text/javascript" src="${path}/assets/scripts/biz/jsAddress.js"></script>
<script>
    var pinleiId = new Array();
    <c:forEach items="${data.bPinlei}" var="pinlei">
    pinleiId.push(${pinlei.id});
    </c:forEach>
    var form;
    $(function () {
        form = $("form").Validform({
            tiptype: 3,
            postonce: true,
            showAllError: true
        });
        $("button[id='btnSave']").click(function (e) {
            if ($("input[name='pinleiId']:checked").length === 0) {
                alert("请选择品类！");
                return;
            }
//            form.ajaxPost(false, true, _path + "/business/save");
            $("form").submit();
        });
        $("input[name='classId']").change(function (e) {
            App.ajax(_path + "/business/queryPinlei", "typeid=7&pid=" + $(this).val(), htmlContent);
        });
        $("button[id='btnDel']").click(function (e) {
            if (confirm("确认删除当前记录？")) {
                App.ajax(_path + "/business/updBatch", "ids=${id}&type=3", function () {
                    window.location.href = _path + "/operate/sjinfo.jsp";
                });
            }
        });
        addressInit('province', 'city', 'county', '北京市', '北京', '海淀区');
        $("#province").val('${data.province}').change();
        $("#city").val('${data.city}').change();
        $("#county").val('${data.county}').change();
        $("input[value='${data.classId}']", $("#classId")).click();
    });
    function htmlContent(data) {
        if (data && data.statusCode === 200) {
            var html = new Array();
            var dataList = data.pinleiList;
            var len = dataList.length;
            if (len > 0) {
                for (var i = 0; i < len; i++) {
                    data = dataList[i];
                    var flag = (i !== 0 && i % 8 === 0);
                    if (flag || i === 0) html.push('<tr>');
                    html.push('<td><label class="radio-inline">');
                    html.push('<input type="checkbox" name="pinleiId" value="' + data.id + '">');
                    html.push('</label></td><td>');
                    html.push(data.value0);
                    html.push('</td>');
                    if (flag) html.push('</tr>');
                }
                var $Pinlei = $("#pinlei");
                $Pinlei.html(html.join(''));
                for (var i = 0, len = pinleiId.length; i < len; i++) {
                    $("input[value='" + pinleiId[i] + "']", $Pinlei).click();
                }
            } else {
                $("#pinlei").html("<tr><td>该分类下暂无品类！</td></tr>");
            }
        } else {
            $("#pinlei").html("<tr><td>加载品类失败！</td></tr>");
        }
    }
</script>
</body>
</html>